#define equ .equ
#define db .db
#define dw .dw
#define block .block
#define fill .fill
#define stop di \ halt

; rst
#define ldrHL(address) rst 08h \ ld hl,address-1
#define ldrDE(address) rst 08h \ ld de,address-1
#define ldrBC(address) rst 08h \ ld bc,address-1
#define ldrA(address) rst 08h \ ld a,(address-1)
#define storHL(address) rst 08h \ ld (address-1),hl
#define storA(address) rst 08h \ ld (address-1),a
#define rectangle(R1x,R1y,R2x,R2y,color) ld h,R1x \ ld l,R1y \ ld d,R2x \ ld e,R2y \ ld a,color \ call DrawCustomRectangle
#define rFastCopy		rst 10h
#define rDrawWrappedString	rst 18h
#define rEndThread		rst 20h

; Special Macros for automatic optimizations
#macro sto(val,loc)
#if val==0
	xor a
#else
	ld a,val
#endif
	ld (loc),a
#endmacro

#macro if(val)	; Optimizations for comparisons with cp
#if val==0
	or a
#else
	cp val
#endif
#endmacro

#macro return(val)	; Optimizations for comparisons with cp
#if val==0
	xor a
	ret
#else
	ld a,val
	ret
#endif
#endmacro

; callr
#macro callr(address)
	rst 08h
	call address-1
#endmacro

#macro callrz(address)
	rst 08h
	call z,address-1
#endmacro

#macro callrnz(address)
	rst 08h
	call nz,address-1
#endmacro

#macro callrpo(address)
	rst 08h
	call po,address-1
#endmacro

; jpr
#macro jpr(address)
	rst 08h
	jp address-1
#endmacro

#macro jprz(address)
	rst 08h
	jp z,address-1
#endmacro

#macro jprnz(address)
	rst 08h
	jp nz,address-1
#endmacro

#macro jprpo(address)
	rst 08h
	jp po,address-1
#endmacro

#macro play(note,length)
#ifdef SOUND
 	ld hl,note
	ld de,length
	call PlaySound
#endif
#endmacro
